package com.zhangmeng;

import com.zhangmeng.callBack.DoConnectionBegin;
import com.zhangmeng.callBack.DoConnectionLost;
import com.zhangmeng.service.MsgHandle;
import com.zhangmeng.service.impl.*;
import com.zhangmeng.utils.Globalobj;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

/**
 * Hello world!
 */
@SpringBootApplication
public class TcpApplication {
    public static void main(String[] args) {
        new TcpServer().start();
        SpringApplication.run(TcpApplication.class, args);
    }

    public static class TcpServer extends Thread {
        @Override
        public void run() {
            ServerImpl.Config config = new ServerImpl.Config();

            //读取配置文件
            Globalobj instance = Globalobj.getInstance();


            config.setName(instance.getName());
            config.setIPVersion("tcp4");
            config.setIP(instance.getHost());
            config.setPort(instance.getTcpPort());
            ServerImpl server = new ServerImpl();
            server.setConfig(config);

            MsgHandle msgHandle =new MsgHandleImpl();
            server.setMsgHandle(msgHandle);
            server.setOnConnStart(new DoConnectionBegin());
            server.setOnConnStop(new DoConnectionLost());
            server.setConnMgr(new ConnManagerImpl());
            server.AddRouter(0,new PingRouter());
            server.AddRouter(1,new HelloRouter());
            server.Start();
        }
    }
}
